package com.wanxi.demo;

import com.wanxi.util.Arrays;

public class Score {
    public static void main(String[] args) {
        int[] arr = new int[6];
        arr = setArray();
        System.out.println(Arrays.toString(arr));
        int max = max(arr);
        int min = min(arr);
        int aver = average(arr, min, max);
        System.out.println("平均分为:" + aver);
    }

    private static int average(int[] arr, int min, int max) {
        int aver = 0;
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
//            if (min != arr[i] && max != arr[i]) {
                sum += arr[i];
//            }
        }
        aver = (sum-min-max) / (arr.length - 2);
        return aver;
    }

    private static int min(int[] arr) {
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (min > arr[i]) {
                min = arr[i];
            }
        }
        return min;
    }

    private static int max(int[] arr) {
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
        }
        return max;
    }

    /**
     * 打分
     *
     * @return
     */
    private static int[] setArray() {
        int[] arr = new int[6];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 20) + 80;
        }
        return arr;
    }
}
